import { genCmptNo } from '@/utils/helper'
const CONTENT_BLOCK_UPDATE_VALUE = 'CONTENT_BLOCK_UPDATE_VALUE'
const CONTENT_BLOCK_RESET = 'CONTENT_BLOCK_RESET'

let I = 0
const state = {
  value: ''
}

const getters = {
  contentBlock (state) {
    return {
      id: genCmptNo(++I),
      type: 'text',
      value: state.value
    }
  }
}

const actions = {
  updateContentValue ({ commit, state, rootState }, value) {
    commit(CONTENT_BLOCK_UPDATE_VALUE, value)
  },
  reset ({ commit, state, rootState }) {
    commit(CONTENT_BLOCK_RESET)
  },
}

const mutations = {
  CONTENT_BLOCK_UPDATE_VALUE (state, value) {
    state.value = value
  },
  CONTENT_BLOCK_RESET (state) {
    state.value = ''
  },
}

export default {
  namespaced: true,
  state,
  getters,
  actions,
  mutations
}
